package org.suburban.talk;
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.suburban.controller.Controller;
import com.google.appengine.api.xmpp.Presence;
import java.util.logging.Logger;
import java.util.logging.Level;
import org.suburban.servlet.XMPPServlet;
/**
 * class to manage client presence
 * @author Alexey Palamarchuk (slonnik@gmail.com)
 *
 */
@SuppressWarnings("serial")
public class XMPPPresenceServlet extends XMPPServlet{
	/** logger*/
	private static final Logger logger = Logger.getLogger(XMPPReceiverServlet.class.getName());
	
	/**
	 * Process incoming request
	 * @param req - incoming request
	 * @param res - outgoing response
	 */
	@Override
	public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {
		
		/** call superclass method*/
		super.doPost(req, res);
		
		/** handle request*/
		try
		{
			Presence presence = xmpp.parsePresence(req);
			Controller.getInstance().handlePresence(presence);
		}
		catch(Exception ex)
		{
			logger.log(Level.WARNING, "Failed to handle presence request: {0}", ex.getMessage());
		}
	}
}
